﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        
        <title>TEST vocJS</title>

        <script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
		<script type="text/javascript" language="javascript" src="https://vocpedia/download/attachments/43876506/voc.js"></script>


        <script type="text/javascript" charset="utf-8">
		(function() {	
		vocJs.extend( {table: {
                   /* 
				   _id: null,
                    name: null,
                    lenght: 0,
                    cols: [],
                    data: [],
                    */
                    // Get row by row index
                    // @param {int} num row index
                    // @return {array}
                    row: function ( num ) {
                        var res = {}; //result
                        var cols = this.cols;
                        if (num && !isNaN( num ) && num < this.data.length) {
                            for (var c in cols) {
                                res[cols[c].name] = this.data[num][cols[c].index]
                            }
                            return res;
                        }
                        return null;
                    },
                    
                    // Get cell value by row index and colunm name
                    // @param {int} num row index
                    // @param {string} col column name
                    // @return {string|int|float}
                    cell: function ( num, col ) {
                        if(num && col && !isNaN( num ) && num < this.data.length
                                && this.hasCol( col ) ) {
                            return this.data[num][this.getColInd(col)];
                        }
                        return null;
                    },
					
                    // Get column index by colunm name
                    // @param {string} col column name
                    // @return {int}
                    getColInd: function ( col ){
                        for( var c in this.cols ) {
                            if ( this.cols[c].name === col ) {
                                return this.cols[c].index;
                            }
                        }
                        return null;
                    },
					
                    // Get column index by colunm name
                    // @param {string} col column name
                    // @return {bool}
                    hasCol: function ( col ) {
                        return (this.getColInd( col ) !== null);
                    }
                }
			});
			})();
			
            var myTable = {
                    _id: "123",
                    name: "MyTable",
                    lenght: 23,
                    cols: [{
                        name: "Column_01",
                        type: "string",
                        index:0
                        },{
                        name: "Column_02",
                        type: "int",
                        index:1
                        },{
                        name: "Column_03",
                        type: "float",
                        index:2
                    }],
                    data: [
                        ["Abc",2,56.5],
                        ["Def",2,56.5],
                        ["Ghi",2,56.5],
                        ["Jkl",2,56.5]
                    ]
                };
                
				
                
        $(function() {
		
			vocJs.extend(myTable,vocJs.table);
			
            var rows = myTable.row(0);
            for(var r in rows) {
                debug(r + ": " + rows[r]);
            }
            debug( myTable.cell(0,"Column_03"));
             
			 var voc = "test";
				
        });//onReady
        
        function debug(text) {
            $('#debug').append(text + '<br>');
        }
        </script>
    </head>
    <body id="boby">
        <div id="container">
            

            <div class="spacer"></div>
            <div id="debug"></div>
            
            
            <div id="error"></div>
            
            
        </div>
    </body>
</html>
